

#import "NameViewController.h"
#import "masonry.h"
#define WIDTH self.view.bounds.size.width
#define HEIGHT self.view.bounds.size.height
@interface NameViewController ()

@end

@implementation NameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UITextField *name = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 2*WIDTH/3, 40)];
    name.center = CGPointMake(WIDTH/2, 100);
    name.tag = 200;
    name.placeholder = @"请输入名字";
    name.borderStyle = UITextBorderStyleRoundedRect;
    name.clearButtonMode = UITextFieldViewModeAlways;
    [name becomeFirstResponder];
    [self.view addSubview:name];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setTitle:@"完成" forState:UIControlStateNormal];
    button.layer.cornerRadius = 20;
    button.clipsToBounds  =YES;
    [button setBackgroundColor:[UIColor orangeColor]];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(done) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(name.mas_centerX);
        make.top.equalTo(name.mas_bottom).offset(10);
        make.width.equalTo(@(2*WIDTH/3));
        make.height.equalTo(@(40));
        
    }];
    
    
    
    
}

-(void)done{
    UITextField *name = (id)[self.view viewWithTag:200];
    NSString *str = name.text;
    
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    [userDef setObject:str forKey:@"name"];
    [userDef synchronize];
    [self dismissViewControllerAnimated:YES completion:nil];
    
    
}



@end
